package com.heima.wemedia.job;

import cn.hutool.core.collection.CollectionUtil;
import com.heima.model.wemedia.pojo.WmNews;
import com.heima.wemedia.service.WmNewsService;
import com.xxl.job.core.context.XxlJobHelper;
import com.xxl.job.core.handler.annotation.XxlJob;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;

@Slf4j
@Component
public class WmNewsAutoPublishHandler {

    @Resource
    private WmNewsService wmNewsService;

    @XxlJob("WmNewsAutoPublish")
    public void wmNewsAutoPublish(){
        //获取待发布文章列表
        List<WmNews> wmNewsList = wmNewsService.getPublishedWmNewsList();
        if (CollectionUtil.isEmpty(wmNewsList)){
            return;
        }
        //调用feign接口发布文章
        wmNewsList.forEach(wmNews -> {
            wmNewsService.publishedWmNews(wmNews);
        });
    }

    @XxlJob("demoJobHandler")
    public void demoTask(){
        log.info("每15秒钟扫描一次待发布、且发布时间已到的文章");
        //获取参数
        String jobParam = XxlJobHelper.getJobParam();
        log.info("任务调度参数:{}",jobParam);
    }

}